// pages/submit-order/submit-order.js
const SERVICE = require("../../service.js");
let openid = ()=>{
  return wx.getStorageSync("token");
}

Page({

  /**
   * 页面的初始数据
   */
  data: {
    remark:""
  },

  /**
   * 生命周期函数--监听页面加载
   * @Data:goodsId_array => 商品id数组
   */
  onLoad: function (options) {
    let _this = this,
      td = this.data,
      goods_id = JSON.parse(options.goodsId_array);
      _this.setData({
        goods_id
      })
    
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成z
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function (options) {
    let _this = this,
    td = this.data,arry = [];
    console.log("页面参数goods_id:", td.goods_id);
    
    for (let i = 0; i < td.goods_id.length; i++) {
      arry.push({ id: td.goods_id[i] });
    }

    wx.showNavigationBarLoading();
    SERVICE.submitOrder({ 'vehicle_json': JSON.stringify(arry), openid: openid() }, (status, data) => {
      wx.hideNavigationBarLoading();
      console.log("提交订单数据:", data);
      _this.setData({
        orderData: data
      });
    });
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  },
  input(e){
    let val = e.detail.value;
    this.setData({
      remark:val
    });
  },
  submit(){
    let td = this.data;
    if (!td.orderData.address){
      wx.showToast({
        title: "您还没有设置收货地址！",
        icon:"none",
        mask:true
      });
    }else{
      // wx.navigateTo({
      //   url: "../pay/pay?orderData=" + JSON.stringify(this.data.orderData) + "&remark=" + td.remark,
      // })
      wx.navigateTo({
        url: "../delivery-time/delivery-time?orderData=" + JSON.stringify(this.data.orderData) + "&remark=" + td.remark,
      });
    }
   
  }
})